﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CityLife.Objects;

namespace CityLife
{
    public partial class Car1 : UserControl, ICar
	{
        public RotateTransform rt = null;
        public TransformGroup tg = null;

        public int InitialRotation = -40;

        public Car1()
		{
			// Required to initialize variables
			InitializeComponent();
            this.tg = new TransformGroup();
            this.SetValue(Canvas.ZIndexProperty, ElementZindex.Car);
		}


        public void DoTurn(Direction direction)
        {
            int basinangle=-40;

            tg.Children.Clear();
            RotateTransform rt = new RotateTransform();
            tg.Children.Add(rt);
            switch (direction)
            {
                case Direction.Top:
                    //animate the turn

                    TranslateTransform ttT = new TranslateTransform();
                    ttT.X = 13;
                    //tt.Y = 15;
                    tg.Children.Add(ttT);


                    rt.Angle = -90 + basinangle;
                  //  rt.CenterX = 15;
                  //  rt.CenterY = 15;
                    CarImage.RenderTransform = tg;
                    break;


                case Direction.Bottom:

                    ////animate the turn
                    ScaleTransform st = new ScaleTransform();
                    st.ScaleX = -1;
                    tg.Children.Add(st);

                    TranslateTransform tt = new TranslateTransform();
                    tt.X =4;
                    //tt.Y = 15;
                    tg.Children.Add(tt);

                    rt.Angle = 90 + basinangle;

               

                 //   rt.CenterX = 15;
                 //   rt.CenterY = 15;

                    CarImage.RenderTransform = tg;
                    break;



                case Direction.Right:


                    rt.Angle = 0 + basinangle;

                    TranslateTransform ttB = new TranslateTransform();
                    ttB.Y = 13;
                    tg.Children.Add(ttB);


                //    rt.CenterX = 15;
                //    rt.CenterY = 15;
                    CarImage.RenderTransform = tg;
                    break;

                case Direction.Left:

                    ////animate the turn
                    ScaleTransform st2 = new ScaleTransform();
                    st2.ScaleY = -1;
                    tg.Children.Add(st2);

                    TranslateTransform ttx = new TranslateTransform();
                    ttx.X = 13;
                    tg.Children.Add(ttx);


                    rt.Angle = 180 + basinangle;
                  //  rt.CenterX = 15;
                  //  rt.CenterY = 15;
                    CarImage.RenderTransform = tg;
                    break;
            }

        }


	}
}